package com.service;

import com.config.WxConfig;
import com.service.IFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class FriendServiceImpl implements IFriendService {

    @Autowired
    private WxConfig wxConfig;

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     *
     * @param set1 好友列表1
     * @param set2 好友列表2
     * @return 共同好友
     */
    @Override
    public Set commonFriends(Set set1, Set set2) {
        List list1=new ArrayList<>(set1);
        List list2=new ArrayList(set2);

        redisTemplate.boundSetOps("s1").add(list1.toArray());
        redisTemplate.boundSetOps("s2").add(list2.toArray());

        Set result=redisTemplate.opsForSet().intersect("s1","s2");  //交集
        return result;
    }
}
